package com.jiu345.users.controller;

import com.jiu345.api.pojo.vo.CartVo;
import com.jiu345.core.page.PageQuery;
import com.jiu345.core.page.TableDataInfo;
import com.jiu345.users.pojo.Address;
import com.jiu345.users.pojo.Order;
import com.jiu345.users.pojo.Region;
import com.jiu345.users.pojo.bo.CartBo;
import com.jiu345.users.pojo.bo.NowBuyBo;
import com.jiu345.users.pojo.bo.OrderBo;
import com.jiu345.users.pojo.vo.OrderVo;
import com.jiu345.users.service.IAddressService;
import com.jiu345.users.service.IOrderService;
import com.jiu345.users.service.IRegionService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.N;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * package:AddressController
 *
 * @author MrLei QQ:235921049
 * desc:用户订单
 * @Date 2024.08.01 21:34
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/user/order")
public class OrderController extends BaseController {
    private final IOrderService orderService;

    /*根据用户ID查询所有订单*/
    @GetMapping("/list")
    public TableDataInfo<Order> list(Order bo, PageQuery pageQuery){
        return orderService.queryPageList(bo,pageQuery);
    }
    /*查询用户待提交订单的商品列表*/
    @GetMapping("/pre")
    public R<OrderVo> createByCart(){
        OrderVo orderPre = orderService.createByCart();
        return R.ok(orderPre);
    }
    /*查询用户立即购买商品*/
    @GetMapping("/pre/now")
    public R<OrderVo> nowBuy(NowBuyBo bo){
        OrderVo orderPre = orderService.nowBuy(bo);
        return R.ok(orderPre);
    }


    /*新增用户订单*/
    @PostMapping()
    public R<Long> add(@Validated(AddGroup.class) @RequestBody OrderBo bo) {
       Order order = orderService.insertByBo(bo);
        //这里保存成功后要返回生成的id？
        return R.ok(order.getId());
    }
}
